package cn.txy.article.mongo;

import cn.txy.article.domain.Article;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.FieldType;

import java.util.Date;

@Data
@Document(collection = "article")//实体类对应mongodb的表/文档article
public class BlogArticle {
    @Id //对应mongodb的表的_id，添加时不设置_id会自动增长
    private String _id;

    private Long id;
    //文章名称
    @Field(name = "articleName",targetType = FieldType.STRING)
    private String articleName;
    //文章标签
    private String articleTagName;
    private Long articleType;
    private Integer articleState;
    private Integer topState;
    private Long publishId;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date createTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date updateTime;
    private Integer articleReadCount;
    private Integer articleStarNum;
    private Integer articleCommentNum;
    private String articleRemark;
    private String articleContent;

    public static BlogArticle of(Article article){
        BlogArticle blogArticle = new BlogArticle();
        //复制对应属性的值  属性和字段必须一致
        BeanUtils.copyProperties(article,blogArticle);
        return blogArticle;
    }

}